package test3;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Choose extends JFrame implements ActionListener {

    JFrame j1, j2;
    JPanel p1, p2;
    JButton[] btn = new JButton[52];
    public String str1 = "", str2 = "";
    Write w1;

    public Choose() {
        j1 = new JFrame("班草选取");
        p1 = new JPanel(new GridLayout(10, 5));
        j1.setBounds(300, 200, 500, 500);
        for (int i = 3; i <= 52; i++) {
            btn[i - 1] = new JButton("" + i);
            btn[i - 1].addActionListener(this);
            p1.add(btn[i - 1]);
        }
        j1.add(p1);
        j1.setVisible(true);


        j2 = new JFrame("班花选取");
        p2 = new JPanel(new GridLayout(2, 1));
        j2.setBounds(800, 200, 300, 200);
        for (int i = 1; i <= 2; i++) {
            btn[i - 1] = new JButton("" + i);
            btn[i - 1].addActionListener(this);
            p2.add(btn[i - 1]);
        }
        j2.add(p2);
        j2.setVisible(true);

    }

    public void actionPerformed(ActionEvent e) {
        for (int i = 3; i <= 52; i++) {
            if (e.getSource() == btn[i - 1]) {
                str1 = "" + i + "/";
                w1 = new Write(str1, "src/election.txt");
                JOptionPane.showMessageDialog(null, "你选择了" + i);
            }
        }
        for (int i = 1; i <= 2; i++) {
            if (e.getSource() == btn[i - 1]) {
                str2 = "" + i + "/";
                w1 = new Write(str2, "src/election.txt");
                JOptionPane.showMessageDialog(null, "你选择了" + i);
            }
        }
        if (str1 != "" && str2 != "") {
            j1.setVisible(false);
            j2.setVisible(false);
        }
    }

}
